﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL = IrisGenerator.Common.DatabaseModel.DataAccess;
using IrisGenerator.Framework.Database;
using IrisGenerator.Common.Tools;

namespace IrisGenerator.Common.DatabaseModel
{
    public class ConstraintType
    {
        public const string PRIMARY_KEY = "PRIMARY";
        public const string FOREIGN_KEY = "FOREIGN KEY";


        public Guid? Identifier { get; set; }
        public string Name { get; set; }


        public static ConstraintType LoadFromName(string name)
        {
            DAL.ConstraintType dbo = null;
            try
            {
                dbo = new DAL.ConstraintType();
                System.Data.DataSet ds = dbo.SelectFromName(name);
                ConstraintType obj = null;
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    if ((ds.Tables[0].Rows.Count > 0))
                    {
                        obj = new ConstraintType();
                        obj.Identifier = SqlConvert.ToGuid(ds.Tables[0].Rows[0]["CONS_TYP_ID"]);
                        obj.Name = SqlConvert.ToString(ds.Tables[0].Rows[0]["CONS_TYP_NAME"]);
                    }
                }
                return obj;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }


        internal static ConstraintType Load(Guid? Id)
        {
            DAL.ConstraintType dbo = null;
            try
            {
                dbo = new DAL.ConstraintType();
                System.Data.DataSet ds = dbo.SelectOne(Id);
                ConstraintType obj = null;
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    if ((ds.Tables[0].Rows.Count > 0))
                    {
                        obj = new ConstraintType();
                        obj.Identifier = SqlConvert.ToGuid(ds.Tables[0].Rows[0]["CONS_TYP_ID"]);
                        obj.Name = SqlConvert.ToString(ds.Tables[0].Rows[0]["CONS_TYP_NAME"]);
                    }
                }
                return obj;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }
    }
}
